package com.zw.yzk.kabu.utils;

import android.content.Context;

import com.zw.yzk.kabu.R;
import com.zw.yzk.kabu.data.utils.RSAUtils;

import org.json.JSONObject;

import java.io.InputStream;

/**
 * Created by zhanwei on 2016/12/28.
 */

public class GetRsaString {

    private Context context;
    private String data;

    public GetRsaString(Context context, String password) {
        this.context = context;
        try {
            JSONObject object = new JSONObject();
            object.put("password", password);
            object.put("timestamp", System.currentTimeMillis());
            data = object.toString();
        } catch (Exception e) {
            data = "";
        }
    }

    public String getRsa() {
        try {
            InputStream inputStream = context.getResources().openRawResource(R.raw.public_key);
            return RSAUtils.encryString(data, inputStream);
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }
}
